import PAGE from '../../../utils/middleware/page'
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import store from '../../../store/index'
const app = getApp()

Page(PAGE({
    behaviors: [storeBindingsBehavior],
    storeBindings: {
        store,
        fields: {
            needNavigate: 'vehicle.needNavigate',
            needNavigatePage: 'vehicle.needNavigatePage'
        },
        actions: {
            updateNeedNavigate: 'vehicle.updateNeedNavigate'
        },

    },
    data: {
        searchParams: {
            PageIndex: 1,
            PageSize: 10,
            MemberPhone: '',
        },
        list: [],
        listField: {
            module: 'member',
            api: 'Search',
            data: 'list'
        },
    },
    onLoad() { },
    onShow() {
        if (this.data.needNavigate) {
            this.updateNeedNavigate(false)
            wx.$Fun.toPage({
                page: this.data.needNavigatePage,
                params: {
                    "0": this.data.member.Id
                }
            })
        }
    },
    handleClear() {
        this.setData({
            list: []
        })
    },
    async handleSearch(e) {
        if (!e.detail || e.detail.length != 11) {
            return
        }
        this.data.searchParams.MemberPhone = e.detail;
        this.fetchList()
    },
    async fetchList() {
        this.handleFetchListData({
            complete: (data) => { }
        }, 'listField', this.data.searchParams.PageIndex == 1)
    },
    handleToPage(e) {
        const { page, id } = e.currentTarget.dataset
        wx.$Fun.toPage({
            page: page,
            params: {
                '0': 0,
                memberId: id
            }
        })
    }
}))